﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace DAO
{
    public static class HoaDonVeDAO
    {
        public static List<HOADON> layDSHoaDonVe()
        {
            QL_HuongRungEntities db = new QL_HuongRungEntities();
            List<HOADON> arrHoaDon = db.HOADON.ToList();
            return arrHoaDon;
        }

        public static int layMaHDLonNhat()
        {
            QL_HuongRungEntities db = new QL_HuongRungEntities();
            try
            {
                int maHD = db.HOADON.Max(p => p.MaHD);
                return maHD;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        public static bool themHoaDon(HOADON hoaDon)
        {
            try
            {
                QL_HuongRungEntities db = new QL_HuongRungEntities();
                db.HOADON.Add(hoaDon);
                db.SaveChanges();
                return true;
            }
            catch (Exception ex) { return false; }
        }

        public static bool capNhatHoaDon(HOADON hoaDon)
        {
            try 
            {
                QL_HuongRungEntities db = new QL_HuongRungEntities();
                HOADON hd = db.HOADON.Find(hoaDon.MaHD);
                hd.CTHD_VEBUFFET = hoaDon.CTHD_VEBUFFET;
                db.SaveChanges();
                return true;
            }
            catch (Exception ex) { return false; }
        }
    }
}